/**
 * Created by xukj on 2018/6/11.
 */
// 每3位数加逗号
Number.prototype.toDollarString = function () {
  if (this === undefined) {
    return '0';
  }

  let numberString = this.toString();
  if (numberString.length <= 3) {
    return numberString;
  }
  else {
    const mod = numberString.length % 3;
    let returnValue = numberString.substr(0, mod);
    for (let i = 0; i < Math.floor(numberString.length / 3); i++) {
      if (mod === 0 && i === 0) {
        returnValue += numberString.substr(mod + i * 3, mod + 3 * i + 3);
      }
      else {
        returnValue += ',' + numberString.substr(mod + 3 * i, mod + 3 * i + 3);
      }
    }
    return returnValue;
  }
}